﻿using Abp.Dependency;
using Abp.Events.Bus;
using Abp.Events.Bus.Handlers;
using Paas.Core.Common.Entities;
using Paas.Core.Const.Enums.Common;

namespace Paas.Core.Common.Events
{
    /// <summary>
    /// 发送通知事件
    /// </summary>
    public class NoticeEvent : EventData
    {
        public EnumNoticeType Type { get; set; }
        public int ObjectId { get; set; }
        public long ToId { get; set; }
        public string Title { get; set; }
        public string Link { get; set; }
        public string Content { get; set; }

    }


    public class NoticeEventHandler : IEventHandler<NoticeEvent>, ITransientDependency
    {
        private readonly IMainRepository<Notice> _noticeRepo;

        public NoticeEventHandler(IMainRepository<Notice> noticeRepo)
        {
            _noticeRepo = noticeRepo;
        }

        public void HandleEvent(NoticeEvent eventData)
        {
            _noticeRepo.InsertAndGetId(new Notice { Type = eventData.Type, ToId = eventData.ToId, Title = eventData.Title, Link = eventData.Link, Content = eventData.Content, IsRead = false });
        }
    }
}

